// run: $exec < input
#include <bits/stdc++.h>

int const maxn = 100007;
int degree[maxn];
int a[maxn];
int ans[maxn];
int n;

std::map<int, std::vector<int>> leaf;
std::vector<std::vector<int>> tree;

void add_edge(int x, int y)
{
	tree[x].push_back(y);
	tree[y].push_back(x);
	degree[x]++;
	degree[y]++;
}

void init()
{
	memset(degree, 0, sizeof(degree));
	tree.clear();
	tree.resize(n + 1);
	leaf.clear();
}

void work(int v, int last, int now)
{
	std::vector<int> tmp{v};
	for (int i = 0; i < (int)tmp.size(); i++) {
		int u = tmp[i];
		for (auto v : tree[u]) {
			degree[v]--;
			if (degree[v] == 1) {
				if (a[v] <= now) tmp.push_back(v);
				else leaf[a[v]].push_back(v);
			}
		}
	}
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	int T; std::cin >> T;
	for (int ti = 1; ti <= T; ti++) {
		std::cout << "Case #" << ti << ": ";
		std::cin >> n;
		init();
		for (int i = 1; i <= n; i++) std::cin >> a[i];
		for (int i = 1; i < n; i++) {
			int x, y; std::cin >> x >> y;
			add_edge(x, y);
		}

		for (int i = 1; i <= n; i++) {
			if (degree[i] != 1) continue;
			leaf[a[i]].push_back(i);
		}

		bool ok = true;
		int last = 0;
		for (int i = 1; i <= n; i++) {
			if (leaf[i].size() > 1) {
				ok = false;
				break;
			} else if (!leaf[i].size()) continue;
			int u = leaf[i][0];
			ans[u] = i;
			for (auto v : tree[u]) {
				degree[v]--;
				if (degree[v] == 1) {
					if (a[v] <= i) work(v, last, i);
					leaf[a[v]].push_back(v);
				}
			}
			last = i;
		}
		if (!ok) std::cout << "Impossible\n";
		else {
		}
	}
}

